//
//  XCBaseModel.m
//  MVVM-ViewModel-NetWork-Model
//
//  Created by 刘小椿 on 16/6/17.
//  Copyright © 2016年 刘小椿. All rights reserved.
//

#import "XCBaseModel.h"

@implementation XCBaseModel

@end

static NSMutableDictionary *_singletons;
@implementation XCBaseModel (Singleton)

+ (instancetype)singleton
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _singletons = [NSMutableDictionary dictionary];
    });
    
    id instance = nil;
    @synchronized(self){
        NSString *klass = NSStringFromClass(self);
        instance = _singletons[klass];
        if(!instance) {
            instance = [[self alloc] init];
            _singletons[klass] = instance;
        }
    }
    return instance;
}

@end
